package com.ruoyi.my.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.annotation.WebTakeTime;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.my.domain.GrXyk;
import com.ruoyi.my.service.IGrXykService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 信用卡Controller
 *
 * @author liuxusheng
 * @date 2022-01-05
 */
@RestController
@RequestMapping("/my/xyk")
public class GrXykController extends BaseController {
    @Autowired
    private IGrXykService grXykService;

/**
 * 查询信用卡列表
 */
@WebTakeTime
@PreAuthorize("@ss.hasPermi('my:xyk:list')")
@GetMapping("/list")
    public TableDataInfo list(GrXyk grXyk) {
        startPage();
        List<GrXyk> list = grXykService.selectGrXykList(grXyk);
        return getDataTable(list);
    }

    /**
     * 导出信用卡列表
     */
    @WebTakeTime
    @PreAuthorize("@ss.hasPermi('my:xyk:export')")
    @Log(title = "信用卡", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GrXyk grXyk) {
        List<GrXyk> list = grXykService.selectGrXykList(grXyk);
        ExcelUtil<GrXyk> util = new ExcelUtil<GrXyk>(GrXyk. class);
        util.exportExcel(response, list, "信用卡数据");
    }

    /**
     * 获取信用卡详细信息
     */
    @PreAuthorize("@ss.hasPermi('my:xyk:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id) {
        return AjaxResult.success(grXykService.selectGrXykById(id));
    }

    /**
     * 新增信用卡
     */
    @PreAuthorize("@ss.hasPermi('my:xyk:add')")
    @Log(title = "信用卡", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GrXyk grXyk) {
        return toAjax(grXykService.insertGrXyk(grXyk));
    }

    /**
     * 修改信用卡
     */
    @PreAuthorize("@ss.hasPermi('my:xyk:edit')")
    @Log(title = "信用卡", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GrXyk grXyk) {
        return toAjax(grXykService.updateGrXyk(grXyk));
    }

    /**
     * 删除信用卡
     */
    @PreAuthorize("@ss.hasPermi('my:xyk:remove')")
    @Log(title = "信用卡", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids) {
        return toAjax(grXykService.deleteGrXykByIds(ids));
    }
}
